package eg;

import java.awt.Color;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Cat {
	private Long id; // identifier

	private Date birthdate;
	private Color color;
	private char sex;
	private float weight;
	private Integer litterId;

	private Cat mother;
	private Set kittens = new HashSet();

	private void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	void setBirthdate(Date date) {
		birthdate = date;
	}

	public Date getBirthdate() {
		return birthdate;
	}

	void setWeight(float weight) {
		this.weight = weight;
	}

	public float getWeight() {
		return weight;
	}

	public Color getColor() {
		return color;
	}

	void setColor(Color color) {
		this.color = color;
	}

	void setSex(char sex) {
		this.sex = sex;
	}

	public char getSex() {
		return sex;
	}

	void setLitterId(int id) {
		this.litterId = id;
	}

	public Integer getLitterId() {
		return litterId;
	}

	void setMother(Cat mother) {
		this.mother = mother;
	}

	public Cat getMother() {
		return mother;
	}

	void setKittens(Set kittens) {
		this.kittens = kittens;
	}

	public Set getKittens() {
		return kittens;
	}

	// addKitten not needed by Hibernate
	public void addKitten(Cat kitten) {
		kitten.setMother(this);
		kitten.setLitterId(kittens.size());
		kittens.add(kitten);
	}

	public boolean equals(Object other) {
		if (this == other)
			return true;
		if (!(other instanceof Cat))
			return false;

		final Cat cat = (Cat) other;

		if (!cat.getLitterId().equals(getLitterId()))
			return false;
		if (!cat.getMother().equals(getMother()))
			return false;

		return true;
	}

	public int hashCode() {
		int result;
		result = getMother().hashCode();
		result = 29 * result + getLitterId();
		return result;
	}
}